package com.health.ts.controller.sysmanage;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.health.ts.constant.ApiResult;
import com.health.ts.controller.BaseController;
import com.health.ts.entity.sysmanage.SysRole;
import com.health.ts.service.sysmanage.SysRoleService;
/**
 * 角色管理
 * @author Administrator
 */
@RestController
@RequestMapping(value = "/api/role",produces= BaseController.JSON_UTF8)
public class RoleController extends BaseController{
	
	@Autowired
	SysRoleService  sysRoleService;
	
	/**
	 * 创建修改角色
	 * @param role
	 * @return
	 */
	@RequestMapping(value="/addRole", method=RequestMethod.POST)
	public ApiResult addRole(@RequestBody SysRole role) {
		sysRoleService.saveOrUpdate(role);
		return ApiResult.success();
    }
	
	/**
	 * 角色删除
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/{id}", method=RequestMethod.DELETE)
	public ApiResult deleteRole(@PathVariable String id) {
		sysRoleService.removeById(id);
		return ApiResult.success();
    }
	
	
	/**
	 * 查询角色列表
	 * @return
	 */
	@RequestMapping(value="/roles", method=RequestMethod.GET)
	public ApiResult listRole(){
		QueryWrapper<SysRole> wrapper = new QueryWrapper<SysRole>();
		wrapper.orderByDesc("create_time");
		List<SysRole> list=sysRoleService.list(wrapper);
		return ApiResult.success(list);
	}
}
